﻿using System;
using System.Collections.Generic;
using System.Reflection;
using Fortune.Attributes.API;

namespace Fortune.API
{
    /// <summary>
    /// 获取当前游戏内全部proto的实现类
    /// </summary>
    [RequestMapping("/proto/_impl")]
    public class ProtosApi : AbstractApi<object>
    {
        protected override object handle(object param)
        {
            List<Dictionary<string,object>> protoList = new List<Dictionary<string, object>>();
            Assembly assembly = typeof(global::Proto).Assembly;
            Type[] types = assembly.GetTypes();
            foreach (Type type in types)
            {
                Type baseType = type.BaseType;
                if (baseType?.Name != nameof(Proto)) continue;
                Dictionary<string, object> dictionary = new Dictionary<string, object>
                {
                    {"name", type.Name},
                    {"namespace", type.Namespace},
                    {"fullName", type.FullName},
                    {"isSerializable", type.IsSerializable},
                    {"isPublic", type.IsPublic},
                    {"assemblyQualifiedName", type.AssemblyQualifiedName},
                    {"GUID", type.GUID.ToString()}
                };
                protoList.Add(dictionary);
            }

            return protoList;
        }
    }
}